package com.example.fistboot.demo;


import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.FileReader;
import java.util.ArrayList;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class Regex_Demo {
    public String fun(String line) {
        if ("".equals(line) || line==null) return "";

        Pattern compile = Pattern.compile("Fact_xlr_kpi_\\d+",Pattern.CASE_INSENSITIVE);
        Matcher matcher = compile.matcher(line);

        int aa=0;
        ArrayList<Integer> list = new ArrayList<>();

        while (matcher.find()){
            if (++aa == 2)
                System.out.println(1);
            int start = matcher.start();
            int end = matcher.end();
//            String substring = line.substring(start, end);
//            line = line.replaceFirst(substring, substring + "_tmp_bug");
            list.add(end);
        }

        for (int size = list.size()-1; size >= 0; size--) {
            Integer i = list.get(size);
            String s1 = line.substring(0, i);
            String s2 = line.substring(i);
            line = s1+"_tmp_bug"+s2;
        }

//        return list dell
        return line;

    }

    public static void main(String[] args) {

        try {

            new BufferedWriter(null).newLine();

            FileReader fileReader =
                    new FileReader("D:\\demodir\\aa.txt");
            BufferedReader reader = new BufferedReader(fileReader);
            String s = reader.readLine();
            while (null!= s ){
                System.out.println(new Regex_Demo().fun(s));

                s = reader.readLine();

            }
            reader.close();
            fileReader.close();
        }catch (Exception e) {
            e.printStackTrace();
        }
    }
}